package reflect;

import java.lang.reflect.Method;

/**
 * 调用有参数方法
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.say("大家好");
        p.say("info:大家好", 10);
        //1.实例化
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        //2.调用方法
        //2.1
        Method method = cls.getMethod("say", String.class);
        //2.2
        method.invoke(obj, "哈哈哈哈哈");

        //2.调用方法
        //2.1
        Method method1 = cls.getMethod("say", String.class, int.class);
        //2.2
        method1.invoke(obj, "我真的栓Q", 10);

    }
}
